﻿Public Class masdrgdosage
    Private DFORM = Nothing
    Private DOSAGEFORM = Nothing
    Private CODE = Nothing
    Private STATUS = Nothing
    Private selectMasdrgdosage = "SELECT `dform` as 'รหัสรูปแบบยา',`dosageform` as 'รูปแบบยา', `code` as 'code รูปแบบยา', `status` as 'สถานะการเปิดใช้งาน' FROM masdrgdosage"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property DFORM_ As Integer
        Get
            Return DFORM
        End Get
        Set(value As Integer)
            DFORM = value
        End Set
    End Property

    Property DOSAGEFORM_ As String
        Get
            Return DOSAGEFORM
        End Get
        Set(value As String)
            DOSAGEFORM = value
        End Set
    End Property

    Property CODE_ As String
        Get
            Return CODE
        End Get
        Set(value As String)
            CODE = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMasdrgdosage_ As String
        Get
            Return selectMasdrgdosage
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMasdrgdosageData()
        If TypeOf DOSAGEFORM Is String Then
            If connect.GetTable("SELECT dform FROM masdrgdosage WHERE dosageform = '" & DOSAGEFORM & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลประเภทยานี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO masdrgdosage (dosageform, code, status) VALUES ('" & DOSAGEFORM & "', '" & CODE & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลรูปแบบยาเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMasdrgdosageData()
        If TypeOf DOSAGEFORM Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE masdrgdosage SET dosageform = '" & DOSAGEFORM & "', code = '" & CODE & "', status = '" & STATUS & "' WHERE dform = '" & DFORM & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลรูปแบบยาเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
